/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package counter.stosc.com;

import javax.microedition.lcdui.*;

/**
 *
 * @author Stosc
 */
class AddCounterUI extends Form implements CommandListener{



    private Controller controller;
    private Command ok = new Command("确定", Command.OK, 0);
    private Command cancel = new Command("取消", Command.CANCEL, 0);
    private TextField counterName = new TextField("修学的内容", "随喜法门", 200, TextField.ANY);
    private TextField scheduleCount = new TextField("预设完成的次数：", "", 20, TextField.NUMERIC);

    public  AddCounterUI(Controller controller) {
        super("新建修学计数器");
        this.controller = controller;
        append(counterName);
        append(scheduleCount);
        addCommand(ok);
        addCommand(cancel);
        setCommandListener(this);
    }

    public void clear() {
        counterName.setString("");
        scheduleCount.setString("");
    }

    public void commandAction(Command c, Displayable d) {
        if(c==cancel)
            controller.handleCommand(Controller.SHOW_LIST_COUNTER, null);
        if(c==ok) {
            Counter counter = new Counter(counterName.getString(), Integer.parseInt(scheduleCount.getString()));
            controller.handleCommand(Controller.DO_ADD_COUNTER, counter);
        }
    }

}
